﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Chaotic.Core.PubMessage;

namespace Chaotic.Core.Extension
{
    public static  class IEventAggregatorExtension
    {
        public static void ResgiterMessage<T>(this IEventAggregator aggregator, Action<T> action)
        {
            aggregator.GetEvent<PubSubEvent<T>>().Subscribe(action, ThreadOption.PublisherThread, true);
        }
        public static void SendMessage<T>(this IEventAggregator aggregator, T message)
        {
            aggregator.GetEvent<PubSubEvent<T>>().Publish(message);
        }


        /// <summary>
        /// 注册提示消息 
        /// </summary>
        /// <param name="aggregator"></param>
        /// <param name="action"></param>
        public static void ResgiterLogMessage(this IEventAggregator aggregator, Action<LogMessageModel> action)
        {
            aggregator.GetEvent<LogMessageEvent>().Subscribe(action, ThreadOption.PublisherThread, true);
        }
 
        /// <summary>
        /// 发送提示消息
        /// </summary>
        /// <param name="aggregator"></param>
        /// <param name="message"></param>
        public static void SendLogMessage(this IEventAggregator aggregator, string message,bool isError =false)
        {
            aggregator.GetEvent<LogMessageEvent>().Publish(new LogMessageModel()
            {
                 Time = DateTime.Now,
                 Message = message,
                 IsError = isError
            });
        }
    }
}
